package com.mall.module.product.domain.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 商品SKU数据传输对象
 */
@Data
@ApiModel("商品SKU信息")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProductSkuDTO {
    @ApiModelProperty(value = "SKU编码(可自动生成)", example = "IPHONE14PM-256-BLACK")
    @Size(max = 50, message = "SKU编码长度不能超过50字符")
    private String skuCode;

    @ApiModelProperty(value = "SKU名称", required = true, example = "iPhone 14 Pro Max 256GB 星空黑")
    @NotBlank(message = "SKU名称不能为空")
    @Size(max = 200, message = "SKU名称长度不能超过200字符")
    private String name;

    @ApiModelProperty(value = "SKU图片(JSON数组)", example = "[\"url1\",\"url2\"]")
    private List<String> images;

    @ApiModelProperty(value = "销售价格", required = true, example = "8999.00")
    @DecimalMin(value = "0.01", message = "价格必须大于0")
    @NotNull(message = "销售价格不能为空")
    private BigDecimal price;

    @ApiModelProperty(value = "市场价", example = "9999.00")
    @DecimalMin(value = "0.01", message = "市场价必须大于0")
    private BigDecimal marketPrice;

    @ApiModelProperty(value = "成本价", example = "7500.00")
    @DecimalMin(value = "0.01", message = "成本价必须大于0")
    private BigDecimal costPrice;

    @ApiModelProperty(value = "库存数量", example = "100")
    @Min(value = 0, message = "库存不能为负数")
    private Integer stock = 0;

    @ApiModelProperty(value = "库存预警值", example = "10")
    @Min(value = 1, message = "预警值最小为1")
    private Integer stockWarning = 10;

    @ApiModelProperty(value = "重量(kg)", example = "0.24")
    @DecimalMin(value = "0.01", message = "重量必须大于0")
    private BigDecimal weight;

    @ApiModelProperty(value = "体积(m³)", example = "0.0005")
    @DecimalMin(value = "0.0001", message = "体积必须大于0")
    private BigDecimal volume;

    @ApiModelProperty(value = "规格数据(JSON对象)", example = "{\"颜色\":\"星空黑\",\"内存\":\"256GB\"}")
    private Map<String, String> specData;

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    @ApiModel("预售配置")
    public static class PresellConfig {
        @ApiModelProperty(value = "预售开始时间", example = "2023-08-01 00:00:00")
        private LocalDateTime startTime;

        @ApiModelProperty(value = "预售结束时间", example = "2023-08-15 23:59:59")
        private LocalDateTime endTime;

        @ApiModelProperty(value = "发货天数", example = "15")
        @Min(value = 1, message = "发货天数至少1天")
        private Integer deliveryDays;
    }

    @ApiModelProperty(value = "预售配置")
    private PresellConfig presellConfig;

    @ApiModelProperty(value = "单次限购数量", example = "2")
    @Min(value = 1, message = "限购数量至少1件")
    private Integer limitPerOrder;
}